﻿using System.Collections.Generic;
using System.Drawing;
using System.Linq;

namespace TowerDefense_MLP
{
    class Wave
    {
        #region ATTRIBUTES
        private List<Enemy> _enemiesList;

        public List<Enemy> EnemiesList
        {
            get { return this._enemiesList; }
        }
        #endregion

        #region METHODS
        public Wave(int enemyType, int size)
        {
            this._enemiesList = new List<Enemy>();
            for (int i = 0; i < size; i++)
            {
                switch (enemyType)
                {
                    case 0:
                        this._enemiesList.Add(new OrcShaman(i));
                        break;

                    case 1:
                        this._enemiesList.Add(new Troll(i));
                        break;

                    case 2:
                        this._enemiesList.Add(new Warrior(i));
                        break;

                    case 3:
                        this._enemiesList.Add(new Dragon(i));
                        break;
                }
            }
        }

        public void MoveEnemies(List<Point> wavePath, ref int lifes)
        {
            List<Enemy> newEnemies = this._enemiesList.Select(e => e.Move(wavePath))
                                                      .Where(en => (en.Position != wavePath.Last())).ToList();

            lifes -= this._enemiesList.Count - newEnemies.Count;

            this._enemiesList.Clear();
            this._enemiesList.AddRange(newEnemies);
        }

        public bool KillEnemy(Enemy e, int damage, TOWER_TYPE tower, out int reward)
        {
            Enemy en = this._enemiesList.Where(i => (i == e)).ToList()[0];
            en.Life -= damage;

            if (en.Life <= 0) // mato o inimigo
            {
                reward = en.RewardValue;
                this._enemiesList.Remove(en);
                return true;
            }
            else
            {
                reward = 0;
                en.HitBy = tower;
                return false;
            }
        }
        #endregion
    }
}
